package com.soho.helper;

import javax.servlet.http.HttpServletRequest;

import com.jfinal.plugin.ehcache.CacheKit;
import com.soho.model.Users;

public class AuthorizerHelper {

	public static boolean checkAccessToken( HttpServletRequest request){
		String _uid				=	UtilsHelper.getParam(request, "uid");
		String _access_token	=	UtilsHelper.getParam(request, "access_token");
		String _cacheKey		=	"checkAccessToken_"+_uid+"_"+_access_token;
		Users _user				=	CacheKit.get(ContentHelper.CACHE_MINUTE,_cacheKey);
		if(!UtilsHelper.checkIsEmpty(_user)){
			return true;
		}
		
		_user					=	Users.dao.findFirst("select id from "+ContentHelper.TABLE_USERS+" where id=? and access_token=?", _uid,_access_token);
		_user					=	Users.dao.findById(1);
		if(UtilsHelper.checkIsEmpty(_user)){
			return false;
		}
		
		CacheKit.put(ContentHelper.CACHE_MINUTE, _cacheKey, _user);
		return true;
	}
}
